<template>
  <div class="app-container">
    <span style="font-size: medium;color: rgba(151,170,195) "> / 采购执行 / 订单跟踪</span>

    <el-row style="margin-top: 20px">
      <el-col :span="24" class="card-box">
        <el-card>
          <el-descriptions title="基本信息" size="large">
            <el-descriptions-item label="订单编号:">{{orderInfo.orderNo}}</el-descriptions-item>
            <el-descriptions-item label="收货地址:">{{ orderInfo.deliveryAddress }}</el-descriptions-item>
            <el-descriptions-item label="订单状态:">
              <el-tag size="large">{{orderInfo.orderStatus}}</el-tag>
            </el-descriptions-item>
            <el-descriptions-item label="负责人:">{{ orderInfo.responsiblePerson }}</el-descriptions-item>
            <el-descriptions-item label="联系电话:">{{ orderInfo.contactPhone }}</el-descriptions-item>
            <el-descriptions-item label="备注:">{{ orderInfo.remarks }}</el-descriptions-item>
          </el-descriptions>
          <div style="display: flex;justify-content: right" v-if="currentOrderStatusIndex >= dictionary['已签收']">
            <el-button type="primary" @click="statusUpdate">
              更新订单状态</el-button>
          </div>
        </el-card>
      </el-col>

      <el-col :span="24" class="card-box">
        <el-card>
          <template #header>
            <Bell style="width: 1em; height: 1em; vertical-align: middle;" />
            <span style="vertical-align: middle; margin-left: 5px">订单状态</span>
          </template>
          <el-row>
            <el-col :span="23">
              <el-steps style="width: 100%"
                        :active="dictionary[orderInfo.orderStatus]"
                        finish-status="success"
                        align-center>
                <el-step class="step" title="待确认" />
                <el-step class="clickable-step" title="已确认">
                  <template #description>
                    <div v-if="currentOrderStatusIndex >= dictionary['已确认']">
                      <el-tag size="default" :type="supplyDetails.length > 0 ? 'primary' : 'info' " style="margin-bottom: 8px;margin-top: 2px"
                              @click="isShowSupplyDetail = true;">货源详情</el-tag>
                      <el-tag size="default" :type="isQualityInfoUpload('出货质检') ? 'primary' : 'info' "
                              @click="isShowQualityInfo = true;qualityInfoTitle = '出货质检';initialFileList()">出货质检</el-tag>
                    </div>
                  </template>
                </el-step>
                <el-step class="clickable-step" title="到出口港">
                  <template #description>
                    <div v-if="currentOrderStatusIndex >= dictionary['到出口港']">
                      <el-tag size="default" :type="isQualityInfoUpload('出港质检') ? 'primary' : 'info' " style="margin-bottom: 8px;margin-top: 2px"
                              @click="isShowQualityInfo = true;qualityInfoTitle = '出港质检';initialFileList()">出港质检</el-tag>
                    </div>
                  </template>
                </el-step>
                <el-step class="clickable-step" title="已发货">
                  <template #description>
                    <div v-if="currentOrderStatusIndex >= dictionary['已发货']">
                      <el-tag size="default" :type="purchaseTrace !== undefined ? 'primary' : 'info' " style="margin-bottom: 8px;margin-top: 2px"
                              @click="isShowPurchaseTrace = true">物流详情</el-tag>
                    </div>
                  </template>
                </el-step>
                <el-step class="clickable-step" title="运送中" >
                  <template #description>
                    <div v-if="currentOrderStatusIndex >= dictionary['运送中']">
                      <el-tag size="default" :type="purchaseTrace !== undefined
                       && purchaseTrace.originLat !== null && purchaseTrace.originLat !== ''? 'primary' : 'info' " style="margin-bottom: 8px;margin-top: 2px"
                              @click="isShowRealTimeInfo = true">实时信息</el-tag>
                    </div>
                  </template>
                </el-step>
                <el-step class="clickable-step" title="已送达" >
                  <template #description>
                    <div v-if="currentOrderStatusIndex >= dictionary['已送达']">
                      <el-tag size="default" :type="isQualityInfoUpload('入港质检') ? 'primary' : 'info' " style="margin-bottom: 8px;margin-top: 2px"
                              @click="isShowQualityInfo = true;qualityInfoTitle = '入港质检';initialFileList()">入港质检</el-tag>
                      <el-tag size="default" :type="purchaseTrace !== undefined
                      && purchaseTrace.receiveManager !== null && purchaseTrace.receiveManager !== '' ? 'primary' : 'info' " style="margin-bottom: 8px;margin-top: 2px"
                              @click="isShowPurchaseTrace = true">物流更新</el-tag>
                    </div>
                  </template>
                </el-step>
                <el-step class="clickable-step" title="已签收" >
                  <template #description>
                    <div v-if="currentOrderStatusIndex >= dictionary['已签收']">
                      <el-tag size="default" :type="purchaseTrace !== undefined
                      && purchaseTrace.receiveManager !== null && purchaseTrace.receiveManager !== ''
                      && purchaseTrace.receiver !== null && purchaseTrace.receiver !== '' ? 'primary' : 'info' " style="margin-bottom: 8px;margin-top: 2px"
                              @click="isShowPurchaseTrace = true">物流更新</el-tag>
                    </div>
                  </template>
                </el-step>
                <el-step class="clickable-step" title="调拨规划" >
                  <template #description>
                    <div v-if="currentOrderStatusIndex >= dictionary['调拨规划']">
                      <el-tag size="default" :type="allocationPlans.length > 0 ? 'primary' : 'info' " style="margin-bottom: 8px;margin-top: 2px"
                              @click="isShowAllocationPlan = true">调拨计划</el-tag>
                    </div>
                  </template>
                </el-step>
                <el-step class="clickable-step" title="配送中" >
                  <template #description>
                    <div v-if="currentOrderStatusIndex >= dictionary['配送中']">
                      <el-tag size="default" type="primary" style="margin-bottom: 8px;margin-top: 2px"
                              @click="showDeliveryDetail">配送明细</el-tag>
                    </div>
                  </template>
                </el-step>
                <el-step class="step" title="已入库" />
              </el-steps>
            </el-col>
            <el-col :span="1">
              <div style="display: flex;justify-content: right;margin-bottom: 5px">
                <el-tag size="large" type="info">待更新</el-tag>
              </div>
              <div style="display: flex;justify-content: right;">
                <el-tag size="large" type="primary">已更新</el-tag>
              </div>
            </el-col>
          </el-row>
        </el-card>
      </el-col>

      <el-col :span="10" class="card-box">
        <el-card style="height: 537px;">
          <template #header>
            <Message style="width: 1em; height: 1em; vertical-align: middle;" />
            <span style="vertical-align: middle; margin-left: 5px">物流信息</span>
          </template>
          <el-scrollbar max-height="457px">
            <el-timeline style="max-width: 600px;margin-right: 60px">
              <el-timeline-item
                  v-for="(activity, index) in logisticDetails"
                  :key="index"
                  :timestamp="activity.updateTime"
                  :type="index === 0 ? 'primary' : 'info'"
              >
                <div>
                  {{activity.logisticMessage}}
                </div>
              </el-timeline-item>
            </el-timeline>
          </el-scrollbar>
        </el-card>
      </el-col>

      <el-col :span="14" class="card-box">
        <el-card>
          <div id="container" style="position: relative; height: 500px; width: 100%"></div>
        </el-card>
      </el-col>
    </el-row>

    <!--货源详情展示-->
    <el-dialog title="货源详情" v-model="isShowSupplyDetail" width="900px" append-to-body>
      <el-scrollbar max-height="450px">
        <el-table :data="supplyDetails">
          <el-table-column type="expand">
            <template #default="props">
              <div
                  v-for="(item, index) in props.row.rawProductDetailList"
                  :key="index"
                  class="sub-row"
                  style="margin-left: 70px"
              >
                <el-descriptions :column="5" class="desc-box">
                  <el-descriptions-item label="货品编码:">{{item.rawProductCode}}</el-descriptions-item>
                  <el-descriptions-item label="货品重量:">{{item.weight}}</el-descriptions-item>
                  <el-descriptions-item label="单位:">{{item.weightUnit}}</el-descriptions-item>
                  <el-descriptions-item label="货品体积:">{{item.volume}}</el-descriptions-item>
                  <el-descriptions-item label="单位:">{{item.volumeUnit}}</el-descriptions-item>
                </el-descriptions>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="货品批号" align="center" prop="rawProductBatch" width="120"/>
          <el-table-column label="货品名称" align="center" prop="name" width="100"/>
          <el-table-column label="供货商" align="center" prop="supplierCode" width="100"/>
          <el-table-column label="原产地" align="center" prop="origin" width="100"/>
          <el-table-column label="牧场" align="center" prop="ranch" width="200"/>
          <el-table-column label="屠宰场" align="center" prop="factory" width="200"/>
          <el-table-column label="饲料" align="center" prop="feed" width="200"/>
          <el-table-column label="疫苗注射情况" align="center" prop="vaccine" width="120"/>
          <el-table-column label="生产日期" align="center" prop="productionDate" width="100">
            <template #default="scope">
              <span>{{ parseTime(scope.row.productionDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="保质期(天)" align="center" prop="shelfLife" width="100"/>
          <el-table-column label="备注" fixed="right" align="center" prop="remarks" width="150"/>
        </el-table>
      </el-scrollbar>
      <template #footer>
        <el-button @click="isShowSupplyDetail = false" type="primary">关 闭</el-button>
      </template>
    </el-dialog>

    <!--质检信息展示-->
    <el-dialog :title="qualityInfoTitle" v-model="isShowQualityInfo" width="500px" append-to-body>
      <el-empty v-show="isQualityInfoEmpty()"></el-empty>
      <div v-for="(info, index) in inspectionInfos" v-show="info !== null && info.inspectionType === qualityInfoTitle" :key="index">
        <el-form :model="info" label-width="100px">
          <el-row>
            <el-col :span="24" class="card-box">
              <el-card>
                <el-form-item label="质检编号：">{{info.inspectionNo}}</el-form-item>
                <el-form-item label="质检时间：">{{info.inspectionTime}}</el-form-item>
                <el-form-item label="质检机构：">{{info.inspectionAgency}}</el-form-item>
                <el-form-item label="质检人：">{{info.inspector}}</el-form-item>
                <el-form-item label="质检结果：">
                  <template #default="scope">
                    <el-tag type="primary" disable-transitions>
                      {{ info.inspectionResult}}
                    </el-tag>
                  </template>
                </el-form-item>
                <el-form-item label="报告附件：">
                  <li :key="file.uid" class="el-upload-list__item ele-upload-list__item-content" v-for="(file, index) in fileList">
                    <el-link :href="file.url.startsWith('http') ? file.url : `${baseUrl}${file.url}`" :underline="false" target="_blank">
                      <span class="el-icon-document"> {{ getFilename(file.name) }} </span>
                    </el-link>
                  </li>
                </el-form-item>
                <el-form-item label="备注：">{{info.remarks}}</el-form-item>
              </el-card>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <template #footer>
        <el-button @click="isShowQualityInfo = false" type="primary">关 闭</el-button>
      </template>
    </el-dialog>

    <!--物流信息展示-->
    <el-dialog title="物流信息" v-model="isShowPurchaseTrace" width="700px" append-to-body>
      <el-empty v-if="purchaseTrace === undefined"></el-empty>
      <div v-if="purchaseTrace !== undefined">
        <el-descriptions title="发货信息" border>
          <el-descriptions-item label="订单编号">{{purchaseTrace.orderNo}}</el-descriptions-item>
          <el-descriptions-item label="物流编号">{{purchaseTrace.logisticNo}}</el-descriptions-item>
          <el-descriptions-item label="出港时间">{{purchaseTrace.departureTime}}</el-descriptions-item>
          <el-descriptions-item label="物流名称">{{purchaseTrace.logisticName}}</el-descriptions-item>
          <el-descriptions-item label="联系电话">{{purchaseTrace.contactPhone}}</el-descriptions-item>
          <el-descriptions-item label="预计到货时间">{{purchaseTrace.expectedDeliveryTime}}</el-descriptions-item>
          <el-descriptions-item label="备注">{{purchaseTrace.departureRemarks}}</el-descriptions-item>
        </el-descriptions>
        <div v-show="currentOrderStatusIndex >= dictionary['已送达']" style="margin-top: 20px">
          <el-descriptions title="到货信息" border>
            <el-descriptions-item label="收货负责人" width="100px">{{purchaseTrace.receiveManager}}</el-descriptions-item>
            <el-descriptions-item label="联系电话">{{purchaseTrace.receiveContact}}</el-descriptions-item>
            <el-descriptions-item label="实际到货时间">{{purchaseTrace.actualDeliveryTime}}</el-descriptions-item>
            <el-descriptions-item label="备注">{{purchaseTrace.receiveRemarks}}</el-descriptions-item>
          </el-descriptions>
        </div>
        <div v-show="currentOrderStatusIndex >= dictionary['已签收']" style="margin-top: 20px">
          <el-descriptions title="收货信息" border>
            <el-descriptions-item label="收货人" width="100px">{{purchaseTrace.receiver}}</el-descriptions-item>
            <el-descriptions-item label="收货时间">{{purchaseTrace.receiveTime}}</el-descriptions-item>
          </el-descriptions>
        </div>
      </div>
      <template #footer>
        <el-button @click="isShowPurchaseTrace = false" type="primary">关 闭</el-button>
      </template>
    </el-dialog>

    <!--调拨规划展示-->
    <el-dialog title="调拨规划" v-model="isShowAllocationPlan" width="900px" append-to-body>
      <el-scrollbar max-height="450px">
        <el-empty description="还未设置调拨计划" v-show="allocationPlans.length === 0"/>
        <el-table :data="allocationPlans" v-show="allocationPlans.length > 0">
          <el-table-column label="调拨编号" align="center" prop="allocationNo"/>
          <el-table-column label="物流商编码" align="center" prop="deliveryCode"/>
          <el-table-column label="物流商" align="center" prop="deliveryName"/>
          <el-table-column label="仓库编号" align="center" prop="warehouseNo"/>
          <el-table-column label="发货地" align="center" prop="origin"/>
          <el-table-column label="调拨时间" align="center" prop="allocationDate">
            <template #default="scope">
              {{ parseTime(scope.row.allocationDate, '{y}-{m}-{d}') }}
            </template>
          </el-table-column>
          <el-table-column label="备注" fixed="right" align="center" prop="remarks"/>
        </el-table>
      </el-scrollbar>
      <template #footer>
        <el-button @click="editAllocationPlan">前往编辑</el-button>
        <el-button @click="isShowAllocationPlan = false" type="primary">关 闭</el-button>
      </template>
    </el-dialog>

    <!--实时信息展示-->
    <el-dialog
        title="实时信息更新"
        v-model="isShowRealTimeInfo"
        width="50%"
        style="border-radius: 12px;
        display: flex;
        flex-direction: column;
        margin: 0 !important;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        max-height: calc(100% - 30px);
        max-width: calc(100% - 30px);
        justify-content: center;"
        :close-on-click-modal="false">
      <el-form ref="realTimeInfoRef" :model="purchaseTrace" label-width="110px" label-position="top" :rules="realTimeRules" style="padding-right: 10px">
        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="出发点经度" prop="originLng">
              <el-input v-model="purchaseTrace.originLng" placeholder="请输入经度" prefix-icon="Location" disabled>
                <template #suffix>
                  <span>°</span>
                </template>
              </el-input>
            </el-form-item>
            <el-form-item label="当前位置经度" prop="currentLng">
              <el-input v-model="purchaseTrace.currentLng" placeholder="请输入经度" prefix-icon="Location" disabled>
                <template #suffix>
                  <span>°</span>
                </template>
              </el-input>
            </el-form-item>
            <el-form-item label="预计到货时间" prop="expectedDeliveryTime">
              <el-date-picker clearable
                              v-model="purchaseTrace.expectedDeliveryTime"
                              value-format="YYYY-MM-DD"
                              placeholder="请选择预计到货时间"
                              style="width: 100%"
                              disabled>
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="出发点纬度" prop="originLat">
              <el-input v-model="purchaseTrace.originLat" placeholder="请输入纬度" prefix-icon="Location" disabled>
                <template #suffix>
                  <span>°</span>
                </template>
              </el-input>
            </el-form-item>
            <el-form-item label="当前位置纬度" prop="currentLat">
              <el-input v-model="purchaseTrace.currentLat" placeholder="请输入经度" prefix-icon="Location" disabled>
                <template #suffix>
                  <span>°</span>
                </template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <template #footer>
        <div class="dialog-footer">
          <el-button @click="isShowRealTimeInfo = false;" type="primary">关 闭</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="LogisticDetail">

import {getPurchaseOrder, updatePurchaseOrderStatus} from "@/api/purchase/purchaseOrder.js";
import {parseTime} from "@/utils/ruoyi.js";
import {Message} from "@element-plus/icons-vue";
import AMapLoader from "@amap/amap-jsapi-loader"
import {onMounted,onUnmounted} from "vue"
import {getOrderDetail} from "@/api/purchase/orderDetail.js";
import {getSupplyDetailByBatches} from "@/api/purchase/supplyDetail.js";
import {listQualityInfoByOrderNo} from "@/api/purchase/qualityInfo.js";
import {getPurchaseTrace} from "@/api/purchase/PurchaseTrace.js";
import {getLogisticDetail, getLogisticDetailByOrderNo} from "@/api/purchase/LogisticDetail.js";
import {ElStep, ElSteps} from "element-plus";
import {getAllocationPlanByOrderNo} from "@/api/purchase/AllocationPlan.js";
import startImage from "@/assets/icons/png/起点.png";
import endImage from "@/assets/icons/png/终点.png";
import shipImage from "@/assets/icons/png/货轮.png";

const {proxy} = getCurrentInstance();

let map = null;

const orderNo = ref('');
const orderInfo = ref({});
const supplyDetails = ref([]);
const inspectionInfos = ref([]);
const purchaseTrace = ref({});
const logisticDetails = ref([]);
const allocationPlans = ref([]);
const dictionary = {
  '待确认': 1,
  '已确认': 2,
  '到出口港': 3,
  '已发货': 4,
  '运送中': 5,
  '已送达': 6,
  '已签收': 7,
  '调拨规划': 8,
  '配送中': 9,
  '已入库': 10
}

const isShowSupplyDetail = ref(false); // 货源详情展示
const isShowQualityInfo = ref(false); // 质检信息展示
const isShowPurchaseTrace = ref(false); // 订单跟踪信息展示
const isShowAllocationPlan = ref(false);
const isShowRealTimeInfo = ref(false);

const currentOrderStatusIndex = ref(1);
const qualityInfoTitle = ref('');
const fileList = ref([]);

onMounted(() => {
  window._AMapSecurityConfig = {
    securityJsCode: "4cb512290cb2f2cde33ae3284c6b8073",
  };
  AMapLoader.load({
    key: "48dff654e078158ff016c701f2755ddf",
    version: "2.0",
    plugins: ["AMap.Scale","AMap.Driving"],
  })
      .then((AMap) => {
        map = new AMap.Map("container", {
          viewMode: "3D", // 是否为3D地图模式
          zoom: 4, // 初始化地图级别
          center: [116.397428, 39.90923],
        });

        const startIcon = new AMap.Icon({
          image: startImage,
          size: new AMap.Size(38, 38),
          imageSize: new AMap.Size(38, 38)
        });

        const endIcon = new AMap.Icon({
          image: endImage,
          size: new AMap.Size(35, 35),
          imageSize: new AMap.Size(35, 35)
        });

        const boatIcon = new AMap.Icon({
          image: shipImage,
          size: new AMap.Size(28, 30),
          imageSize: new AMap.Size(28, 30)
        });

        //终点标记
        setTimeout(() => {
          let endPoint =[];
          if(orderInfo.value.destinationLng !== null && orderInfo.value.destinationLat !== null
              && orderInfo.value.destinationLng !== 0.0 && orderInfo.value.destinationLat !== 0.0){
            endPoint = [orderInfo.value.destinationLng, orderInfo.value.destinationLat];
            const endMaker =  new AMap.Marker({
              position: endPoint,
              icon: endIcon,
              offset: new AMap.Pixel(-10, -28),
            });
            map.add(endMaker);
            map.setCenter(endPoint);
          }
        }, 500);

        //起点标记
        setTimeout(() => {
          if(purchaseTrace.value !== undefined
              && purchaseTrace.value.originLat !== null){
            const startMaker =  new AMap.Marker({
              position: [purchaseTrace.value.originLng, purchaseTrace.value.originLat],
              icon: startIcon,
              offset: new AMap.Pixel(-10, -28),
            });
            map.add(startMaker);
            map.setCenter([purchaseTrace.value.originLng, purchaseTrace.value.originLat]);
          }
        }, 1000);

        //货船标记
        setTimeout(() => {
          if(purchaseTrace.value !== undefined
              && purchaseTrace.value.currentLat !== null){
            const boatMaker =  new AMap.Marker({
              position: [purchaseTrace.value.currentLng, purchaseTrace.value.currentLat],
              icon: boatIcon,
              offset: new AMap.Pixel(-10, -28),
            });
            boatMaker.on('click',()=>{
              openBoatInfo();
            })
            map.add(boatMaker);
            map.setCenter([purchaseTrace.value.currentLng, purchaseTrace.value.currentLat]);
            openBoatInfo();
          }
        }, 1500);
      })
      .catch((e) => {
        console.log(e);
      });
})

onUnmounted(() => {
  map?.destroy();
})

function openBoatInfo(){
  const content = computed(() => [
    `<div style="font-size: small"><b>${orderInfo.value.orderStatus}</b>`,
    `当前位置:经(${purchaseTrace.value.currentLng})/ 纬(${purchaseTrace.value.currentLat})`,
    `预计到达时间:${purchaseTrace.value.expectedDeliveryTime}</div>`
  ]);
  const infoWindow = new AMap.InfoWindow({
    content: content.value.join('<br>'),
    anchor: 'top-left',
  });
  infoWindow.open(map, [purchaseTrace.value.currentLng, purchaseTrace.value.currentLat]);
}

function initial(){
  if(proxy.$route.query.orderNo){
    orderNo.value = proxy.$route.query.orderNo;
    getPurchaseOrder(orderNo.value).then(response => {
      orderInfo.value = response.data;
      currentOrderStatusIndex.value = dictionary[orderInfo.value.orderStatus];
    })
    getOrderDetail(orderNo.value).then(response => {
      let orderDetails = response.data;
      if(orderDetails.length > 0){
        let rawProductBatches = orderDetails.map(item => item.rawProductBatch);
        getSupplyDetailByBatches(rawProductBatches).then(response => {
          supplyDetails.value = response.data;
        })
      }
    })
    listQualityInfoByOrderNo(orderNo.value).then(response => {
      inspectionInfos.value = response.data;
    })
    getPurchaseTrace(orderNo.value).then(response => {
      purchaseTrace.value = response.data;
    })
    getAllocationPlanByOrderNo(orderNo.value).then(response => {
      allocationPlans.value = response.data;
    })
    getLogisticDetailByOrderNo(orderNo.value).then(response => {
      logisticDetails.value = response.data;
    })
  }
}

/** 截取url获取文件名*/
function getFilename(url) {
  return url.substring(url.lastIndexOf('/') + 1);
}

/** 状态更新 */
function statusUpdate(){
  let currentStatus = convert(currentOrderStatusIndex.value);
  if(currentStatus === '已入库'){
    proxy.$modal.msgWarning('当前订单状态为已入库，无法进行状态更新！')
    return;
  }
  if(currentStatus === '调拨规划' && allocationPlans.value.length === 0){
    proxy.$modal.msgWarning('请先完善调拨计划信息！')
    return;
  }
  let nextStatus = convert(currentOrderStatusIndex.value + 1);
  proxy.$modal.confirm('是否确认将订单状态由\'' + currentStatus + '\'更新为\''
      + nextStatus + '\'，修改后\'' + currentStatus + '\'状态下的信息将无法修改？')
      .then(function() {
        orderInfo.value.orderStatus = nextStatus;
        updateOrderStatus();
  })
}

/** 更新状态至调拨规划 */
function updateOrderStatus(){
  updatePurchaseOrderStatus(orderInfo.value).then(response => {
    proxy.$modal.msgSuccess("状态更新成功");
    initial();
  })
}

/** 将状态编号转化为状态名称 */
function convert(index){
  for (let dictionaryKey in dictionary) {
    if(dictionary[dictionaryKey] === index){
      return dictionaryKey;
    }
  }
}

/** 跳转到采购调拨编辑调拨计划 */
function editAllocationPlan(){
  proxy.$router.push({
    path:'/AllocationPlan',
    query:{
      orderNo: orderNo.value
    }
  });
}

/** 判断质检信息空状态是否展示 */
function isQualityInfoEmpty(){
  for(let i = 0; i < inspectionInfos.value.length; i++){
    if(inspectionInfos.value[i].inspectionType === qualityInfoTitle.value){
      return false;
    }
  }
  return true;
}

/** 输入质检类型返回是否存在 */
function isQualityInfoUpload(type){
  for(let i = 0; i < inspectionInfos.value.length; i++){
    if(inspectionInfos.value[i].inspectionType === type){
      return true;
    }
  }
  return false;
}

/** 跳转到调拨明细 */
function showDeliveryDetail(){
  if(allocationPlans.value.length === 0){
    proxy.$modal.msgWarning('暂无调拨明细！')
    return;
  }
  proxy.$router.push({
    path:'/DeliveryDetail',
    query:{
      allocationNo: allocationPlans.value[0].allocationNo
    }
  });
}

/** 初始化文件列表 */
function initialFileList(){
  inspectionInfos.value.forEach(item => {
    if(item.inspectionType === qualityInfoTitle.value){
      const list = item.reportAttachment.split(',');
      fileList.value = list.map(item => {
        if (typeof item === "string") {
          item = { name: item, url: item };
        }
        return item;
      });
    }
  })
}

initial()
</script>

<style scoped lang="scss">
#container{
  width: 100%;
  height: 100%;
}
.demo-tabs > .el-tabs__content {
  padding: 32px;
  color: #6b778c;
  font-size: 32px;
  font-weight: 600;
}
.clickable-step {
  cursor: pointer;
}
.sub-row {
  padding: 12px;
  border-bottom: 1px solid #ebeef5;

  &:last-child {
    border-bottom: none;
  }
}
.desc-box {
  :deep(.el-descriptions__header) {
    display: none; /* 隐藏标题 */
  }

  :deep(.el-descriptions__body) {
    background: transparent;
  }
}
</style>